package com.ruoyi.web.controller.bl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bl.domain.BlBrand;
import com.ruoyi.bl.service.IBlBrandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌配置，用于管理供应商供应的商品Controller
 *
 * @author ruoyi
 * @date 2023-08-19
 */
@RestController
@RequestMapping("/bl/brand")
public class BlBrandController extends BaseController
{
    @Autowired
    private IBlBrandService blBrandService;

    /**
     * 查询品牌配置，用于管理供应商供应的商品列表
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlBrand blBrand)
    {
        startPage();
        List<BlBrand> list = blBrandService.selectBlBrandList(blBrand);
        return getDataTable(list);
    }

    /**
     * 导出品牌配置，用于管理供应商供应的商品列表
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:export')")
    @Log(title = "品牌配置，用于管理供应商供应的商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlBrand blBrand)
    {
        List<BlBrand> list = blBrandService.selectBlBrandList(blBrand);
        ExcelUtil<BlBrand> util = new ExcelUtil<BlBrand>(BlBrand.class);
        util.exportExcel(response, list, "品牌配置，用于管理供应商供应的商品数据");
    }

    /**
     * 获取品牌配置，用于管理供应商供应的商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:query')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return success(blBrandService.selectBlBrandByBrandId(brandId));
    }

    /**
     * 新增品牌配置，用于管理供应商供应的商品
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:add')")
    @Log(title = "品牌配置，用于管理供应商供应的商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlBrand blBrand)
    {
        blBrand.setCreateBy(getUsername());
        return toAjax(blBrandService.insertBlBrand(blBrand));
    }

    /**
     * 修改品牌配置，用于管理供应商供应的商品
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:edit')")
    @Log(title = "品牌配置，用于管理供应商供应的商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlBrand blBrand)
    {
        blBrand.setUpdateBy(getUsername());
        return toAjax(blBrandService.updateBlBrand(blBrand));
    }

    /**
     * 删除品牌配置，用于管理供应商供应的商品
     */
    @PreAuthorize("@ss.hasPermi('bl:brand:remove')")
    @Log(title = "品牌配置，用于管理供应商供应的商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Long[] brandIds)
    {
        return toAjax(blBrandService.deleteBlBrandByBrandIds(brandIds));
    }
}
